﻿using HPIT_Library;
using HPIT_Library_Modal;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace HPIT_Library_DAL
{
  public  class BorrowBooksSerives
    {
        public static DataTable Select()
        {
          string  sql = "select * from BorrowBooks,member,Books where Books.BookId=BorrowBooks.BookId and member.id=BorrowBooks.BookMemberId";
            return DbHelper.ExecuteTable(sql);
        }
        public static int Update(int BorrowBooksId)
        {
            string sql = "update BorrowBooks set EndTime=GETDATE(),BookRevert=1 where BorrowBooksId="+BorrowBooksId;
            
            return DbHelper.ExecuteNonQuery(sql);

        }
        public static int Insert(BorrowBooks borrowBooks)
        {
            string sql =string.Format( "insert into BorrowBooks values({0},GETDATE(),null,0,{1})",borrowBooks.BookId,borrowBooks.BookMemberId);
            return DbHelper.ExecuteNonQuery(sql);
        }
        //public static BorrowBooks SelectID(int BorrowBooksId)
        //{
        //    string sql = "select * from BorrowBooks where BorrowBooksId=@BorrowBooksId";
        //    SqlParameter sqlParameters = new SqlParameter("@BorrowBooksId", BorrowBooksId);
               
        //    SqlDataReader reader = DbHelper.ExecuteReader(sql, sqlParameters);
        //    BorrowBooks borrowBooks = null;
        //    if (reader.Read())
        //    {
        //        borrowBooks = new BorrowBooks()
        //        { 
        //            BorrowBooksId=Convert.ToInt32(reader["BorrowBooksId"])
        //        };
        //    }
        //    reader.Close();
        //    return borrowBooks;
        //}

    }
}
